<?php

namespace Admin\Controller;

class AddressController extends AdminbaseController {

    function _initialize() {
        parent::_initialize();
        $this->currentModel = D("Address");
    }

    //首页
    public function index() {

        $requestMap = $this->convertRequestToMap();

        //分页
        $count = $this->currentModel->getListCount($requestMap);
        $page = $this->page($count, C("DEFAULT_PAGE_SIZE"));

        //获取列表
        $list = $this->currentModel->queryForList($page, $requestMap);

        $this->assign("statusEnum", C("DEFAULT_YN"));
        $this->assign('list', $list);
        $this->assign("page", $page->show('Admin', $this->parameter));
        $this->display();

    }

    /**
     * 添加数据
     */
    public function addPost() {

        $addressData["name"] = I("post.name");
        $addressData["address"] = I("post.address");
        $addressData["create_time"] = getCurrentDate();

        $this->currentModel->add($addressData);

        $this->success("添加成功", U("address/index"));

    }

    /**
     * 更新数据
     */
    public function editPost() {

        $id = $_REQUEST["id"];

        $address = $this->currentModel->queryById($id);

        $address["name"] = I("post.name");
        $address["address"] = I("post.address");

        $this->currentModel->updateInfo($address);

        $this->success("更新成功", U("address/index"));

    }


}